const user = {
    state: localStorage.getItem('userState') ? JSON.parse(localStorage.getItem('userState')) : {
        user: {
            username: ''
        }
    },
    getters: {
        getUser(state) {
            return state.user
        }
    },
    mutations: {
        updateUser(state, user) {
            state.user = user
            console.log(JSON.stringify(user));
            localStorage.setItem('userState', JSON.stringify(user))
        },
        logout(state) {
            localStorage.removeItem('userState');
            state.user.username = '';
        }
    },
    actions: {
        asyncUpdateUser(context, user) {
            console.log('updateUser');
            context.commit('updateUser', user)
        },

        asyncLogout(context) {
            console.log('logout');
            context.commit('logout');
        }

    }
}

export default user;